package com.bravo;

import com.bravo.callbackinfs.OrderService;
import com.bravo.callbackinfs.callTolm;
import com.bravo.event.MyEvent;
import com.bravo.framework.BravoApplicationContext;
import com.bravo.listeners.CarService;
import com.bravo.listeners.SmsService;
import org.junit.Before;
import org.junit.Test;

/**
 * @Auther: Min.Liu
 * @Description:
 * @Date: Created in 14:19 2024/6/11
 */
public class DemoTest {
    // 之所以设计成public static，是为了能在OrderService中拿到SmsService，毕竟我没实现Autowired自动注入
    public static BravoApplicationContext applicationContext;
    public static  SmsService smsService;
    public static OrderService orderService;
    public static CarService carService;

    @Before
    public void initApplicationContext() {
        applicationContext = new BravoApplicationContext();
        smsService =  (SmsService) applicationContext.getBean("com.bravo.listeners.SmsService");
        orderService = (OrderService) applicationContext.getBean("com.bravo.callbackinfs.OrderService");
        carService = (CarService) applicationContext.getBean("com.bravo.listeners.CarService");
    }

    @Test
    public void testSpringEvent() {
        // 用户下单（试着点进去，把orderService发布的事件改为OtherEvent）
        //orderService.order();
        //applicationContext.publishEvent(new OtherEvent(orderService));
        applicationContext.publishEvent(new MyEvent(new callTolm()));
    }

}
